package com.myproject.thread.interrupt;

import org.junit.Test;

//没有阻塞的情况，调用interrupt会将isInterrupted状态改为true
public class IsInterruptTest1 {

    public static boolean flag = true;


    public static void main(String[] args) throws InterruptedException {

        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("start");
                while (flag){}
                System.out.println("end");
            }
        });
        t1.start();

        System.out.println("t1 isInterrupted state is " + t1.isInterrupted());

        t1.interrupt();
        Thread.sleep(1000);
        System.out.println("t1 isInterrupted state is " + t1.isInterrupted());

        t1.interrupt();
        Thread.sleep(1000);
        System.out.println("t1 isInterrupted state is " + t1.isInterrupted());

        t1.interrupt();
        Thread.sleep(1000);
        System.out.println("t1 isInterrupted state is " + t1.isInterrupted());
    }

}
